//弹出框
function dialog(id, time, url) {
    dialogClose();

    $(".mask").width($(document).outerWidth(true));
    $(".mask").height($(window).height());
    $(".mask").show();
    $(id).show();

    $('body').css('overflow', 'hidden');
    var dw = $(id + " .alert").outerWidth() / 2;
    var dh = $(id + " .alert").outerHeight() / 2;
    $(id + " .alert").css({ "margin-top": -dh + "px" });
    var dw2 = $(id + " .dialog_content").outerWidth() / 2;
    var dh2 = $(id + " .dialog_content").outerHeight() / 2;
    $(id + " .dialog_content").css({ "margin-left": -dw2 + "px", "margin-top": -dh2 + "px" });

    // 弹框，图片居中
    // $('.dialog .showImg').css({ 'display': 'flex', 'flex-direction': 'column', 'justify-content': 'center' });

    //假如有时间参数time，会定时关闭弹出框
    if (time) {
        setTimeout(dialogClose, time);
    }
    if (url) {
        setTimeout(function() { dialogUrl(url); }, time);
    }
}

function dialogUrl(url) {
    window.location.href = url;
}

function dialogClose() {
    $(".dialog").hide();
    $(".mask").hide();
    $('body').css('overflow', 'auto');
}

function resizeRoot() {
    var deviceWidth = document.documentElement.clientWidth,
        num = 750,
        num1 = num / 100;
    if (deviceWidth > num) {
        deviceWidth = num;
    }
    document.documentElement.style.fontSize = deviceWidth / num1 + "px";
}
//根节点HTML的字体大小初始化
resizeRoot();

window.onresize = function() {
    resizeRoot();
};

const url = 'http://test.jckaola.com/App/Api/h5_access';
const domain = 'http://test.jckaola.com/web';

//获取路径？后字段
function GetQueryString(name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
    var r = window.location.search.substr(1).match(reg);
    if (r != null) return decodeURI(r[2]);
    return '';
}

// 时间戳转年/月/日
function getDate(date) {
    var date = new Date(date * 1000);
    var Y = date.getFullYear() + '/';
    var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '/';
    var D = (date.getDate() < 10 ? '0' + (date.getDate()) : date.getDate()) + ' ';
    return Y + M + D;
}

//判断是否是安卓还是ios  
function isAndroid_ios() {
    var u = navigator.userAgent,
        app = navigator.appVersion;
    var isAndroid = u.indexOf('Android') > -1 || u.indexOf('Linux') > -1; //android终端或者uc浏览器  
    var isiOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); //ios终端  
    return isAndroid == true ? true : false;
}

// 判断是否为苹果x
function isIphoneX() {
    return /iphone/gi.test(navigator.userAgent) && (screen.height == 812 && screen.width == 375)
}

// 判断是否为中文
function isChineseChar(str) {
    var reg = /^[\u4e00-\u9fa5]+$/;
    return reg.test(str);
}

// 计算字符串长度
function getBLen(str) {
    if (str == null) return 0;
    if (typeof str != "string") {
        str += "";
    }
    return str.replace(/[^\x00-\xff]/g, "01").length;
}

// 判断是否为苹果x
$(() => {
    if (isIphoneX()) {
        console.log('我是苹果x');
        $('.inhetop').css("padding", ".88rem .24rem .38rem");
        $('.header .hetitle').css('padding-top', '.88rem');
        $('.m2').css('padding', '1.76rem 0 0 0');
        $('.my_top_bg').css('height', '3.74rem');
        $('.userCard').css('top', '2.25rem');
        $('.padT13_5').css('padding-top', '1.93rem');
        $('.searchInput ').css('top', '.88rem');
        $('.inheder2').css('height', '4.18rem');
        $('.headline_top_bg ').css('height', '2.98rem');
        $('.m5').css('padding', '1.68rem 0 1.24rem 0');
    }
})